package com.gitee.wsl.compose.chart.polar.axis

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember

/**
 * A model for a radial axis that uses Float values and is linear.
 *
 * @param tickValues Values for each tick on the axis. Must have at least 2 values.
 */
 class FloatRadialAxisModel(
    override val tickValues: List<Float>,
) : RadialAxisModel<Float> {
    init {
        require(tickValues.size >= 2) { "tickValues must have at least 2 values " }
    }

    private val sortedTickValues = tickValues.sorted()
    private val range = sortedTickValues.last() - sortedTickValues.first()

     override fun computeOffset(point: Float): Float {
        return (point - sortedTickValues.first()) / range
    }
}

@Composable
 fun rememberFloatRadialAxisModel(tickValues: List<Float>): FloatRadialAxisModel =
    remember(tickValues) { FloatRadialAxisModel(tickValues) }


@Composable
fun RadialAxisModel.Companion.Float(tickValues: List<Float>) = rememberFloatRadialAxisModel(tickValues)